﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BTL
{
    public partial class HDnhap : Form
    {
        BAL.hdnhapBAL _hdnhapBAL;
        VO.hdnhapVO _hdnhapVO;
        public HDnhap()
        {
            InitializeComponent();
        }

        private void data()
        {
            _hdnhapVO = new VO.hdnhapVO();
            _hdnhapVO.Mancc = box_mancc.Text;
            _hdnhapVO.Mdhd = box_mancc.Text;
            _hdnhapVO.Ngaynhap = Convert.ToDateTime(box_ngaynhap.Text);
            _hdnhapVO.Tennv = box_manv.Text;
        }
        private void bt_them_Click(object sender, EventArgs e)
        {
            try
            {
                _hdnhapBAL = new BAL.hdnhapBAL();
                data();
                _hdnhapBAL.hdnhap_them(_hdnhapVO);
                HDnhap_Load(sender,e);
                MessageBox.Show("Thành công","Thêm Thành Công",MessageBoxButtons.OK);
            }
            catch
            {
                MessageBox.Show("Lỗi", "Có lỗi xảy ra, xem help", MessageBoxButtons.OK);
            }
        }

        private void buttonX1_Click(object sender, EventArgs e)
        {
            _hdnhapBAL = new BAL.hdnhapBAL();
            dataGridViewHoaDonnhap.DataSource = _hdnhapBAL.hdnhap_xem();
        }
        private void databind()
        {
            box_mahd.DataBindings.Clear();
            box_mahd.DataBindings.Add("text",dataGridViewHoaDonnhap.DataSource,"MaHD");
            box_mancc.DataBindings.Clear();
            box_mancc.DataBindings.Add("text", dataGridViewHoaDonnhap.DataSource, "MaNCC");
            box_manv.DataBindings.Clear();
            box_manv.DataBindings.Add("text", dataGridViewHoaDonnhap.DataSource, "TenNV");
        }
        private void HDnhap_Load(object sender, EventArgs e)
        {
            buttonX1_Click(sender, e);
            databind();
        }

        private void bt_sua_Click(object sender, EventArgs e)
        {
            try
            {
                _hdnhapBAL = new BAL.hdnhapBAL();
                data();
                _hdnhapBAL.hdnhap_sua(_hdnhapVO);
                HDnhap_Load(sender, e);
                MessageBox.Show("Thành công", "Sua Thành Công", MessageBoxButtons.OK);
            }
            catch
            {
                MessageBox.Show("Lỗi", "Có lỗi xảy ra, xem help", MessageBoxButtons.OK);
            }
        }

        private void bt_xoa_Click(object sender, EventArgs e)
        {
            try
            {
                _hdnhapBAL = new BAL.hdnhapBAL();
                _hdnhapVO = new VO.hdnhapVO();
                _hdnhapVO.Mdhd = box_mahd.Text;
                _hdnhapBAL.hdnhap_xoa(_hdnhapVO);
                HDnhap_Load(sender, e);
                MessageBox.Show("Thành công", "Xoa Thành Công", MessageBoxButtons.OK);
            }
            catch
            {
                MessageBox.Show("Lỗi", "Có lỗi xảy ra, xem help", MessageBoxButtons.OK);
            }
        }

        private void bt_thoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void buttonX2_Click(object sender, EventArgs e)
        {
            frmHelp _fm = new frmHelp();
            _fm.Show();
        }

        private void buttonX3_Click(object sender, EventArgs e)
        {
            cthdnhap _cthdnhap = new cthdnhap();
            _cthdnhap.Show();
        }
    }
}
